package com.vehicle.service.imp;

import com.vehicle.bean.Menu;
import com.vehicle.mapper.PermissionMapper;
import com.vehicle.pojo.Permission;
import com.vehicle.service.MenuService;
import com.vehicle.util.BuildMenus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImp implements MenuService {
    @Autowired
    private PermissionMapper permissionMapper;
    @Override
    public List<Menu> indexLeftMenu(Integer uid) {
        List<Menu> menus=new ArrayList<>();
        List<Permission> permissions = permissionMapper.selectPermissionsByUid(uid);
        for (Permission p:
             permissions) {
            Menu menu=new Menu();
            menu.setParentid(p.getParentid());
            menu.setPid(p.getPid());
            menu.setTitle(p.getName());
            menu.setHref(p.getHref());
            menu.setIcon(p.getIcon());
            menu.setSpread(p.getOpen()==1?true:false);
            menus.add(menu);
        }
        return BuildMenus.build(menus,1);
    }
}
